<?php

$api = app('Dingo\Api\Routing\Router');

$params = [
    'middleware' => ['api'],
//    'limit' => 600,
    'expires' => 1
];

$api->version('v1', $params, function ($api) {
    $api->group(['namespace' => 'App\Http\Controllers\Admin\V1'], function ($api) {
        // 登录
        $api->post('login', 'LoginController@login')->name('api.login');
        // 注册
        $api->post('register', 'RegisterController@store')->name('api.register');

        $api->get('refresh', 'LoginController@refresh', ['middleware' => ['jwt.refresh']])->name('api.refresh');

        $api->group(['middleware' => ['api.auth']], function ($api) {
            // me
            $api->get('me', 'LoginController@me')->name('api.me');

            $api->get('logout', 'LoginController@logout')->name('api.logout');
        });
    });

    $api->group(['prefix' => 'admin'], function ($api) {
        $api->group(['middleware' => ['api.auth', 'operation.log']], function ($api) {

            //获取OSS token
            $api->group(['namespace' => 'App\Http\Controllers\Auth\V1'],function ($api){
                $api->get('oss/token','OssController@getConfig')->name('oss.token');
            });

            $api->group(['namespace' => 'App\Http\Controllers\Admin\V1'], function ($api) {

                $api->get('/index','IndexController@index')->name('index');

                // 需要一个超级管理员中间件
                $api->group(['middleware' => ['role:super_admin']], function ($api) {

                    // 角色管理
                    $api->resource('roles', 'RoleController');

                    // 权限管理 需要超级管理才能访问
                    $api->resource('permissions', 'PermissionController', ['except' => ['destroy']]);

                    // 部门管理
                    $api->get('sections/list/{section}','SectionController@getList')->name('sections.list');
                    $api->post('sections/status/{section}', 'SectionController@status')->name('sections.status');
                    $api->get('section/count','SectionController@count')->name('sections.count');
                    $api->resource('sections', 'SectionController');

                    // 网站基础配置管理 只能查看和修改
                    $api->resource('settings', 'SettingController', ['except' => ['store', 'destroy']]);

                    // 重置密码
                    $api->patch('users/{user}/password', 'UserController@password')->name('users.password');
                    // 下载模板
                    $api->get('users/export', 'UserController@export')->name('users.export');
                    // 用户导入
                    $api->post('users/import', 'UserController@import')->name('users.import');
                    // 人员管理
                    $api->resource('users', 'UserController');
                });

                // 考后成绩管理
                $api->resource('test_results', 'StudentResultController', ['except' => ['update', 'destroy']]);

                // 试卷管理
                // 试卷添加预览
                $api->get('test_list/add', 'TestListController@add')->name('test_list.add');
                // 添加时查询试题数据
                $api->post('test_list/select_questions', 'TestListController@selectQuestions')->name('test_list.selectQuestions');
                // 复制试卷
                $api->post('test_list/copy/{test_list}', 'TestListController@copy')->name('test_list.copy');
                // 预览试卷
                $api->get('test_list/preview/{test_list}', 'TestListController@preview')->name('test_list.preview');
                // 导出
                $api->post('test_list/export/{test_list}', 'TestListController@export')->name('test_list.export');
                $api->resource('test_list', 'TestListController');

                // 分类
                $api->resource('categories', 'CategoryController', ['except' => ['show']]);

                // 下载题库Excel模板
                $api->get('questions/excel', 'QuestionController@excel')->name('questions.excel');
                // 导出题库
                $api->get('questions/export', 'QuestionController@export')->name('questions.export');
                // 导入题库
                $api->post('questions/import', 'QuestionController@import')->name('questions.import');
                // 修改题目状态
                $api->patch('questions/status', 'QuestionController@status')->name('questions.status');
                // 题库管理
                $api->resource('questions', 'QuestionController');

                //考试管理
                $api->get('examinations/category/list', 'ExaminationController@getCategoryList')->name('examinations.category');
                $api->get('examinations/export', 'ExaminationController@export')->name('examinations.export');
                $api->put('examinations/delayed/{examination}','ExaminationController@delayed')->name('examination.delayed');
                $api->resource('examinations', 'ExaminationController');

                // 登录日志
                $api->get('login/logs/export', 'LoginLogController@export')->name('login.export');
                $api->get('login/logs/count', 'LoginLogController@count')->name('login.count');
                $api->get('login/logs', 'LoginLogController@index')->name('login.log');

                // 操作日志
                $api->get('operation/logs', 'OperationLogController@index')->name('operation.log');
            });
        });
    });
});
